(() => {
  let asyncId = location.search.split("?")[1].split("&");
  let stateJie = null;
  let l_id = asyncId[0];
  let h_id = asyncId[1];
  let uid = null;
  let type = null;
  let is_jin = null;
  let is_guan = null;
  let zufangNum = 1;
  let obj = {};
  let ele = {};
  let numX = 1;
  let is_in = 1;
  ele.xinfeng = $("#xinfeng");
  ele.xinfeng2 = $("#xinfeng2");
  ele.inp = $("#inp");
  ele.cha = $("#cha");
  ele.cha2 = $("#cha2");
  ele.neibu_Dong = $("#neibu_Dong");
  ele.lingqu2 = $("#lingqu2");
  ele.left_jian = $("#left_jian");
  ele.left_jia = $("#left_jia");
  ele.left_jian2 = $("#left_jian2");
  ele.left_jia2 = $("#left_jia2");
  ele.clare1 = $("#clare1");
  ele.clare2 = $("#clare2");
  ele.modal_estate = $("#modal-estate");
  ele.center_num = $("#center_num");
  ele.center_num2 = $("#center_num2");
  ele.quren_btn = $("#quren_btn");
  ele.modal_code = $("#modal-code");
  ele.modal_xinfeng = $("#modal-xinfeng");
  ele.modal_lease = $("#modal-lease");
  ele.chahao4 = $("#chahao4");
  ele.chahao2 = $("#chahao2");
  ele.top_img = $("#top_img");
  ele.bot_home = $("#bot_home");
  ele.top_height = $("#top_height");
  ele.zone_body = $("#zone_body");
  ele.bot_home_li = $("#bot_home_li");
  ele.modal_prohibit = $("#modal-prohibit");
  ele.modal_operate = $("#modal-operate");
  ele.modal_fangguan = $("#modal-fangguan");
  ele.renewal = $("#renewal");
  ele.title_name = $("#title_name");
  ele.activity_top = $("#activity_top");
  ele.zhongzhi = $("#zhongzhi");
  ele.zh_name = $("#zh_name");

  ele.activity_bottom = $("#activity_bottom");
  ele.ruzhu_top = $("#ruzhu_top");
  ele.wuye = $("#wuye");
  ele.right_btn = $("#right_btn");
  ele.modal_tuizu = $("#modal-tuizu");
  ele.quxiao2 = $("#quxiao2");
  ele.qunren2 = $("#qunren2");
  ele.chahao5 = $("#chahao5");
  ele.laiyuan_left = $("#laiyuan_left");
  ele.shiyongDui = $("#shiyongDui");
  ele.quren_btn2 = $("#quren_btn2");
  ele.textarns = $("#textarns");
  ele.modal_textarn = $("#modal-textarn");
  ele.cha3 = $("#cha3");
  ele.quxiao4 = $("#quxiao4");
  ele.queren4 = $("#queren4");
  ele.xuzuMoney = $("#xuzuMoney");
  ele.zongNum = $("#zongNum");
  ele.zupin2 = $("#zupin2");
  ele.chengName = $("#chengName");
  ele.title_guan = $("#title_guan");
  ele.zuke = $("#zuke");
  ele.guanjiaZuke = $("#guanjiaZuke");
  ele.guanjiaDui = $("#guanjiaDui");
  ele.jinImg = $("#jinImg");
  ele.guanjiaId = $("#guanjiaId");
  ele.zukeBtn = $("#zukeBtn");
  ele.chahao6 = $("#chahao6");
  ele.queren5 = $("#queren5");
  ele.fgtuique = $("#fgtuique");
  ele.fgtui = $("#fgtui");
  ele.fgcha = $("#fgcha");
  ele.modal_leasing = $("#modal-leasing");
  ele.dwts = $("#dwts");
  ele.yijianqqqun = $("#yijianqqqun");
  ele.daojishi = $("#daojishi");
  ele.qqqun = $("#qqqun");

  let list = ["", "", "", "", "", ""];
  // 我的房间所在位置
  let my_house = {};
  ele.zongNum.innerHTML = obj.xz_money * numX;
  ele.center_num2.innerHTML = numX;
  leaveTime();
  initAsync();
  sessionStorage.setItem("refresh", "true");
  // 点击上面返回，则返回楼层
  ele.top_img.onclick = () => {
    // 刘欣 引导 2023-6-21 19:00:20
    let ugid = guide.getUsersGuideId("userGuideId");
    // 兑换礼包码
    if (~[108].indexOf(ugid)) {
      guide.hideCheap_108();
      guide.showCheap_109();
    }
    // 引导 招财猫 返回到能量房产
    else if (~[132].indexOf(ugid)) guide.hideCentury_132();
    history.back();
  };

  // 点击差，叉掉介绍信
  ele.cha.onclick = () => {
    closeMdl(ele.modal_xinfeng);
  };
  // 点击信封打开信封
  ele.xinfeng2.onclick = () => {
    openMdl(ele.modal_xinfeng);
  };
  ele.left_jian2.onclick = () => {
    if (numX <= 1) {
      return;
    }
    numX--;
    ele.center_num2.innerHTML = numX;
    ele.zongNum.innerHTML = obj.xz_money * numX;
  };
  ele.left_jia2.onclick = () => {
    if (numX >= 2) {
      return;
    }
    numX++;
    ele.center_num2.innerHTML = numX;
    ele.zongNum.innerHTML = obj.xz_money * numX;
  };
  // // 点击信封打开信封
  // ele.xinfeng2.onclick = () => {
  //   // openMdl(ele.modal_xinfeng);
  //   openTips("暂无介绍信可用！");
  // };
  // 点击差后关闭兑换
  ele.cha2.onclick = () => {
    closeMdl(ele.modal_code);
    // 刘欣 引导 2023-6-21 18:55:14
    let ugid = guide.getUsersGuideId("userGuideId");
    // 兑换礼包码
    if (~[107].indexOf(ugid)) {
      guide.hideCheap_107();
      guide.showCheap_108();
    }
  };
  // 点击立即领取后打开兑换
  ele.lingqu2.onclick = () => {
    ele.inp.value = "";
    openMdl(ele.modal_code);
    // 刘欣 引导 2023-6-21 14:55:14
    let ugid = guide.getUsersGuideId("userGuideId");
    // 兑换礼包码
    if (~[106, 107].indexOf(ugid)) {
      guide.hideCheap_106();
      guide.showCheap_107();
    }
  };
  // !一键加群

  // !点击确认之后获取到value里值
  ele.quren_btn.onclick = () => {
    let inpVal = ele.inp.value.trim();
    if (inpVal.length == 0) {
      ele.inp.value = "";
      return openTips("请输入兑换码！");
    }
    // 发请求
    codeAsunc(inpVal);
  };
  // 点击来源
  ele.laiyuan_left.onclick = () => {
    openTips("加入官方QQ群可获得");
  };
  // 点击更改广告
  ele.right_btn.onclick = () => {
    openMdl(ele.modal_textarn);
  };
  // 点击插
  ele.cha3.onclick = () => {
    ele.textarns.value = "";
    closeMdl(ele.modal_textarn);
  };
  //! 点击使用兑换码
  ele.shiyongDui.onclick = () => {
    closeMdl(ele.modal_xinfeng);
    location.href = `../page/each_building.html?${2}`;
    // let token = getCookie("token");
    // ajax({
    //   method: "get",
    //   url: API_PATH.DUIHUAN,
    //   header: {
    //     Authorization: token,
    //   },
    //   success: (res) => {
    //     openTips(res.msg);
    //     if (res.code == 1) {
    //       initAsync();
    //       closeMdl(ele.modal_xinfeng);
    //     }
    //   },
    //   error: (err) => {
    //     // openTips(err.msg);
    //   },
    // });
  };
  // 点击租凭房产关闭步进器
  ele.clare1.onclick = () => {
    zufangNum = 1;
    ele.center_num.innerHTML = zufangNum;
    closeMdl(ele.modal_estate);
  };
  // 点击续租房产关闭步进器
  ele.clare2.onclick = () => {
    numX = 1;
    ele.center_num2.innerHTML = numX;
    ele.zongNum.innerHTML = obj.xz_money * numX;
    closeMdl(ele.modal_lease);
  };
  //! 判断是不是廉租房
  if (h_id == 1) {
    openMdl(ele.activity_top);
    closeMdl(ele.activity_bottom);
  } else {
    closeMdl(ele.activity_top);
    openMdl(ele.activity_bottom);
  }

  //todo 点击房东对用户操作的x
  ele.chahao2.onclick = () => {
    closeMdl(ele.modal_operate);
  };
  // 房东点击禁止续租按钮
  ele.renewal.onclick = () => {
    // todo关闭设置按钮打开禁止续租提示
    closeMdl(ele.modal_operate);
    // openMdl(ele.modal_prohibit);
  };
  //todo 禁止续租点击取消
  ele.quxiao4.onclick = () => {
    closeMdl(ele.modal_prohibit);
  };
  //todo 方管退租
  ele.fgtui.onclick = () => {
    closeMdl(ele.modal_fangguan);
  };
  //todo 方管退租
  ele.fgcha.onclick = () => {
    closeMdl(ele.modal_fangguan);
  };
  // todo点击确认禁止续租
  ele.queren4.onclick = () => {
    blockZu({
      l_id: l_id,
      h_id: h_id,
      uid: uid,
    });
  };
  // todo房管点击确认禁确认续租
  ele.fgtuique.onclick = () => {
    // !房管退租
    blockZu({
      l_id: l_id,
      h_id: h_id,
      uid: uid,
      is_gj: 1,
    });
  };
  // todo点击取消
  ele.quxiao2.onclick = () => {
    closeMdl(ele.modal_tuizu);
  };
  // todo点击叉号
  ele.chahao5.onclick = () => {
    closeMdl(ele.modal_tuizu);
  };
  // todo点击确认发请求
  ele.qunren2.onclick = () => {
    // 刘欣 引导 确认退租 2023-6-22 13:15:29
    let ugid = guide.getUsersGuideId("userGuideId");
    if (~[109].indexOf(ugid)) guide.hideCheap_109();
    tuizu();
  };
  // todo房东点击续租确认后发请求
  ele.zupin2.onclick = () => {
    xuzuFang();
  };
  // todo房东点击确认更改公告
  ele.quren_btn2.onclick = () => {
    messageFang(ele.textarns.value);
  };
  // todo被房东退租提示
  ele.queren5.onclick = () => {
    closeMdl(ele.modal_leasing);
    is_in = 0;
  };
  ele.chahao6.onclick = () => {
    closeMdl(ele.modal_leasing);
    is_in = 0;
  };
  // 租凭房产点击加
  ele.left_jia.onclick = () => {
    zufangNum++;
    ele.center_num.innerHTML = zufangNum;
  };
  // 租凭房产点击减
  ele.left_jian.onclick = () => {
    if (zufangNum == 1) {
      return;
    }
    zufangNum--;
    ele.center_num.innerHTML = zufangNum;
  };

  // };
  // !发送退租请求
  function tuizu() {
    let token = getCookie("token");
    ajax({
      method: "get",
      url: API_PATH.TUIZU,
      header: {
        Authorization: token,
      },
      success: (res) => {
        openTips(res.msg);
        if (res.code == 1) {
          closeMdl(ele.modal_tuizu);
          setTimeout(() => {
            history.back();
          }, 500);
        }
      },
      error: (err) => {
        // openTips(err.msg);
      },
    });
  }
  // !发请求输入兑换码兑换
  function codeAsunc(data) {
    let token = getCookie("token");
    ajax({
      method: "post",
      url: API_PATH.CODE,
      header: {
        Authorization: token,
      },
      data: {
        code: data,
      },
      success: (res) => {
        openTips(res.msg);
        if (res.code == 1) {
          closeMdl(ele.modal_code);
          // 在请求一次
          initAsync();
          // 刘欣 引导 2023-6-23 17:25:38
			let ugid = guide.getUsersGuideId("userGuideId");
          // 兑换礼包码
          if (~[107].indexOf(ugid)) guide.hideCheap_107();
        }
      },
      error: (err) => {
        // openTips(err.msg);
      },
    });
  }
  // !发送请求来请求房间数据
  function initAsync() {
    let token = getCookie("token");
    ajax({
      method: "get",
      url: API_PATH.HOMELIST,
      header: {
        Authorization: token,
      },
      data: {
        l_id: l_id,
        h_id: h_id,
      },
      success: (res) => {
        list = res.data.list;
        obj = res.data.detail;
        my_house = res.data.detail.my_house;
        ele.qqqun.innerHTML = res.data.detail.QQ_num;
        initList(res.data.detail);
      },
      error: (err) => {
        // openTips(err.msg);
      },
    });
  }
  // 初始化模板数据

  function initList(data) {
    // !判断是否禁租
    if (my_house && my_house.is_jin == 1) {
      // 判断是否为房东
      if (my_house.type == 1) {
        ele.neibu_Dong.innerHTML = `
        <p>你的房产已经被出售或者被竞拍,请前往房产交易中心进行查看</p>
        `;
      } else {
        let daoqi = data.my_over_day;
        let time3 = setInterval(() => {
          if (daoqi * 1000 <= +new Date()) {
            closeMdl(ele.modal_leasing);
            clearInterval(time3);
          }
          let n = null;
          list.forEach((item) => {
            if (item.type == 1) {
              n = 1;
            }
          });
          if (n == 1) {
            ele.zhongzhi.innerHTML = `你已经被房东终止续租`;
          } else {
            ele.zhongzhi.innerHTML = `你已经被管家终止续租`;
          }
          ele.daojishi.innerHTML = `会在${getCountTime(daoqi)}之后自动退出`;
        }, 1000);
      }
      if (is_in == 1) {
        openMdl(ele.modal_leasing);
      } else {
        closeMdl(ele.modal_leasing);
      }
    }
    // 渲染物业费
    if (h_id != 1 && h_id != 2) {
      ele.wuye.innerHTML = `物业费:${data.wy_money}金/天`;
      openMdl(ele.wuye);
    } else {
      closeMdl(ele.wuye);
    }
    // 头部标题
    ele.title_name.innerHTML = data.house_name;

    // !是否显示上面的介绍信------------------------------------------------
    if (data.has_QQ == 1) {
      openMdl(ele.activity_bottom);
      closeMdl(ele.activity_top);
    }
    if (data.has_QQ == 0) {
      openMdl(ele.xinfeng2);
      closeMdl(ele.xinfeng);
    } else {
      closeMdl(ele.xinfeng2);
      openMdl(ele.xinfeng);
      // 公告通知
      if (my_house.type != 2 && h_id != 1) {
        // todo说明是房东
        openMdl(ele.right_btn);
      } else {
        closeMdl(ele.right_btn);
      }
    }
    ele.xinfeng.onclick = () => {
      openTips("请兑换兑换码!");
    };
    // 渲染右上角的入住人数
    ele.ruzhu_top.innerHTML = `${obj.user_num ? obj.user_num : ""}/${
      list[0] ? list[0].zf_num : ""
    }`;
    let newList = list
      .map((item, index) => {
        return `
      <li id="${
        item.id == my_house.id ? "home_my" : "home_my1"
      }" class="home_list" data-id="${
          item.luxury
        }" style="background: url('http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/beij${bg(
          item.luxury
        )}.png') no-repeat;background-size: 100% 100%">
    
          <div style="display:${
            my_house.id == item.id && h_id != 1 ? "block" : "none"
          };" class="zhao" id="zhaocm">
          <img src="http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/zhaocaimao.png" class="zhaocaimao" alt="" />
          <p class="zhaocai">招财进宝</p>
        </div>
      
      <div class="top_left">
      <p style="display:${item.type == 1 && h_id == 2 ? "block" : "none"};">
        <span class="btn_name"><span class="time1" data-time="${
          data.over_day
        }" data-id="${item.type}" id="time_daoqi"></span>
        <span style="display:${
          my_house.type == 1 && h_id == 2 ? "block" : "none"
        };" id="xuzu" class="xuzu">续租</span>
        </span>
      </p>
      <p class="ferBox" style="display:${
        item.type == 2 || item.type == 3 ? "block" : "none"
      };"> <span style="display:flex;">排名：${item.rank} <span data-type="${
          item.type
        }" style="display:${
          my_house.id == item.id ? "block" : "none"
        };" class="tuichu" id="tuichu">退租</span></span><p/>
      <p style="display:${item.type == 1 ? "block" : "none"};">${
          h_id == 2 ? "楼主" : "房东"
        }：<span>${
          item.info && item.info.nick_name ? item.info.nick_name : "天天来收租"
        }</span>${offline(item.leave_time)}</p>
      <p style="display:${item.type == 2 ? "block" : "none"};">租客：<span>${
          item.info && item.info.nick_name ? item.info.nick_name : "天天来收租"
        }</span>${offline(item.leave_time)}</p>
      <p style="display:${item.type == 3 ? "block" : "none"};">房管：<span>${
          item.info && item.info.nick_name ? item.info.nick_name : "天天来收租"
        }</span>${offline(item.leave_time)}</p>
      <p>个人豪华值：<span>${item.luxury}</span></p>
      <p style="display:${
        item.team_luxury ? "block" : "none"
      };">团队豪华值：<span>${
          item.team_luxury ? item.team_luxury : "0"
        }</span></p>
    </div>
    <div class="top_right">
      <div class="top_t">
        <img src="http://img.qxgs.cc/tiantianlaishouzu/img/yuanshi/MG_NL.png" alt="" /><span
          >${item.power}/小时</span
        >
      </div>
      <p style="display:${item.type == 1 ? "block" : "none"};">入住:<span>${
          obj.user_num
        }/${item.zf_num}</span></p>
    </div>
    <!-- 下方按钮 -->
    <div id="zhuangxiu" style="display:${
      my_house.id == item.id && h_id != 1 ? "block" : "none"
    };" class="li_btn ${
          my_house.id == item.id && h_id != 1 ? "guide-zhuangxiu" : ""
        }">装修</div>
    <!-- 这是右下角的信息 -->
    <div  class="bottom_right">
      <div style="display: ${
        item.type == 2 && h_id == 2 && my_house.type == 1 ? "block" : "none"
      }" id="prohibit" data-name="${
          item.info && item.info.nick_name ? item.info.nick_name : "微风"
        }" data-id="${item.agent_id}" class="jin">
        <img
          src="http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/jinzhi.png"
          class="jinzhi"
          alt=""
        />
        <p>禁止续租</p>
      </div>
      <div style="display: ${
        item.type == 2 && (h_id == 3 || h_id == 4) && my_house.type == 3
          ? "block"
          : "none"
      }" id="prohibit" data-name="${
          item.info && item.info.nick_name ? item.info.nick_name : "微风"
        }" data-id="${item.agent_id}" class="jin">
        <img
          src="http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/jinzhi.png"
          class="jinzhi"
          alt=""
        />
        <p>禁止续租</p>
      </div>
    <div id="setting" data-time="${item.over_day}" data-user="${
          obj.user_num
        }" data-zf="${item.zf_num}" data-jin="${item.is_jin}" data-id="${
          item.agent_id
        }" data-type="${item.type}" style="display:${
          // todo这个是判断只有房东视角有设置按钮
          my_house.type == 1 && item.type != 1 && h_id != 2 && h_id != 1
            ? "block"
            : "none"
        };" class="jin">
      <img
        src="http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/setting.png"
        class="jinzhi"
        alt=""
      />
      <p>设置</p>
    </div>
      <!-- 下面的道具 -->
      <div class="daoju">
        <div class="lin_ju"  style="display:${
          item.today_qf ? "block" : "none"
        };">
          <span>今日:</span
          ><img
            src="http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/bianliqian.png"
            alt=""
          /><span>x${item.today_qf}</span>
        </div>
        <div class="lin_ju" style="display:${item.all_qf ? "block" : "none"};">
          <span>累计:</span
          ><img
            src="http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/bianliqian.png"
            alt=""
          /><span>x${item.all_qf}</span>
        </div>
      </div>
    </div>
            </li>`;
      })
      .join(" ");
    // !新的我自己的
    let newListS = list
      .map((item, index) => {
        return ` 
       <li id="${
         item.id == my_house.id ? "home_my" : "home_my1"
       }" class="home_list home_lists" data-id="${
          item.luxury
        }" style="background: url('http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/beij${bg(
          item.luxury
        )}.png') no-repeat;background-size: 100% 100%">
        <div class="${item.id == my_house.id ? "top_bg" : "top_bg2"}">
              <div class="lzl_img_left">
                <div class="lzl_img"><img src="${
                  item.info && item.info.head_pic
                    ? IMG_DOMAIN + item.info.head_pic
                    : item.info && item.info.sex && item.info.sex == 1
                    ? "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx1.png"
                    : "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx2.png"
                }" alt=""></div>
                <div class="lzl_cen">
                    <p style="display:${
                      item.type == 1 ? "block" : "none"
                    };"><span>${
          item.info && item.info.nick_name ? item.info.nick_name : "夏天的风"
        }</span></p>
      <p style="display:${item.type == 2 ? "block" : "none"};"><span>${
          item.info && item.info.nick_name ? item.info.nick_name : "夏天的风"
        }</span></p>
      <p style="display:${item.type == 3 ? "block" : "none"};"><span>${
          item.info && item.info.nick_name ? item.info.nick_name : "夏天的风"
        }</span></p>
                    <p style="display:${
                      item.type == 1 ? "block" : "none"
                    };">ID: <span>${
          item.agent.invite_code
        }</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;身份：${
          h_id == 2 ? "楼主" : "房东"
        }</p>
      <p style="display:${item.type == 2 ? "block" : "none"};">ID: <span>${
          item.agent.invite_code
        }</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;身份：租客</p>
      <p style="display:${item.type == 3 ? "block" : "none"};">ID: <span>${
          item.agent.invite_code
        }</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;身份：房管</p>


                </div>
              </div>
              <div class="lzl_left">
                <p>${offline(item.leave_time)}</p>
                <div class="lzl_right_1">
                  <img src="http://img.qxgs.cc/tiantianlaishouzu/img/yuanshi/MG_NL.png" alt="">
                  <span>${item.power}/小时</span>
                </div>
              </div>
            </div>
      <div class="top_left">
      <p style="display:${item.type == 1 && h_id == 2 ? "block" : "none"};">
        <span class="btn_name"><span class="time1" data-time="${
          data.over_day
        }" data-id="${item.type}" id="time_daoqi"></span>
      
        </span>
      </p>

      <p>个人豪华值：<span>${item.luxury}</span></p>
      <p style="display:${
        item.team_luxury ? "block" : "none"
      };">团队豪华值：<span>${
          item.team_luxury ? item.team_luxury : "0"
        }</span></p>
          <!-- 下面的道具 -->
      <div class="daoju">
          <p style="display:${item.type == 1 ? "block" : "none"};">入住:<span>${
          obj.user_num
        }/${item.zf_num}</span></p>
        <div class="lin_ju"  style="">
        <div style="display:${item.today_qf ? "block" : "none"};">
        <div style="display: flex;align-items: center;">
          <span>今日:</span
          ><img
            src="http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/bianliqian.png"
            alt=""
          /><span>x${item.today_qf}</span>
          </div>
        </div>
        </div>
        <div class="lin_ju" style="">
        <div style="display:${item.all_qf ? "block" : "none"};">
         <div style="display: flex;align-items: center;">
       
          <span>累计:</span
          ><img
            src="http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/bianliqian.png"
            alt=""
          /><span>x${item.all_qf}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
     <p style="display:${item.type == 1 && h_id == 2 ? "block" : "none"};">
        <span class="btn_name"><span class="time1" data-time="${
          data.over_day
        }" data-id="${item.type}" id="time_daoqi"></span>
        <span style="display:${
          my_house.type == 1 && h_id == 2 ? "block" : "none"
        };" id="xuzu" class="xuzu">续租</span>
        </span>
      </p>
    <p class="ferBox" style="display:${
      item.type == 2 || item.type == 3 ? "block" : "none"
    };"> <span style="display:flex;"><span data-type="${
          item.type
        }" style="display:${
          my_house.id == item.id ? "block" : "none"
        };" class="tuichu" data-id="${item.agent_id}" id="tuichu" guide-id=${
          my_house.id == item.id ? "1" : ""
        }>退租</span></span><p/>
    <p class="ferBox" style="display:${
      my_house.type == 1 && item.type == 1 ? "block" : "none"
    };"> <span style="display:flex;"><span data-type="${
          item.type
        }" style="display:${"block"};" class="tuichu" data-id="${
          item.agent_id
        }" id="tuichufang" guide-id=${
          my_house.id == item.id ? "1" : ""
        }>退出</span></span><p/>
    <div class="top_right">
  
  
    </div>
    <!-- 下方按钮 -->
    <div id="zhuangxiu" style="display:${
      my_house.id == item.id && h_id != 1 ? "block" : "none"
    };" class="li_btn ${
          my_house.id == item.id && h_id != 1 ? "guide-zhuangxiu" : ""
        }">装修</div>
    <!-- 这是右下角的信息 -->
    <div  class="bottom_right">
        <div style="display: ${
          item.type == 2 && h_id == 2 && my_house.type == 1 ? "block" : "none"
        }" id="prohibit" data-name="${
          item.info && item.info.nick_name ? item.info.nick_name : "微风"
        }" data-id="${item.agent_id}" class="jin">
        <img
          src="http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/jinzhi.png"
          class="jinzhi"
          alt=""
        />
        <p>禁止续租</p>
      </div>
      <div style="display: ${
        item.type == 2 && (h_id == 3 || h_id == 4) && my_house.type == 3
          ? "block"
          : "none"
      }" id="prohibit" data-name="${
          item.info && item.info.nick_name ? item.info.nick_name : "微风"
        }" data-id="${item.agent_id}" class="jin">
        <img
          src="http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/jinzhi.png"
          class="jinzhi"
          alt=""
        />
        <p>禁止续租</p>
      </div>
    <div id="setting" data-time="${item.over_day}" data-user="${
          obj.user_num
        }" data-zf="${item.zf_num}" data-jin="${item.is_jin}" data-id="${
          item.agent_id
        }" data-type="${item.type}" style="display:${
          // todo这个是判断只有房东视角有设置按钮
          my_house.type == 1 && item.type != 1 && h_id != 2 && h_id != 1
            ? "block"
            : "none"
        };" class="jin">
      <img
        src="http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/setting.png"
        class="jinzhi"
        alt=""
      />
      <p>设置</p>
    </div>
    
    </div>
            </li>
            `;
      })
      .join(" ");
    // 渲染模板
    ele.bot_home_li.innerHTML = newListS;
    // !获取下面的高度
    // 父盒子高度
    let fer_box = ele.zone_body.offsetHeight;
    // 获取上方高度
    let top_height = ele.top_height.offsetHeight;
    //  动态设置下面的ui高度
    ele.bot_home.style.height = fer_box - top_height + 31 + "px";
    // 让页面自动滚动到指定位置获取dom
    ele.home_my = $("#home_my");
    if (my_house.type == 2) {
      if (ele.home_my) {
        ele.home_my.scrollIntoView();
      }
    }
    // !配背景------------
    let home_listAll = document.querySelectorAll(".home_list");
    home_listAll.forEach((item) => {
      let hao = item.dataset.id;
      if (h_id == 1) {
        item.style.background = `url('http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/beij5.png') no-repeat`;
        item.style.backgroundSize = "100% 100%";
      } else if (hao < 400) {
        item.style.background = `url('http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/beij11.png') no-repeat`;
        item.style.backgroundSize = "100% 100%";
      } else if (hao < 1000) {
        item.style.background = `url('http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/beij12.png') no-repeat`;
        item.style.backgroundSize = "100% 100%";
      } else if (hao < 1700) {
        item.style.background = `url('http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/beij13.png') no-repeat`;
        item.style.backgroundSize = "100% 100%";
      } else if (hao < 2400) {
        item.style.background = `url('http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/beij14.png') no-repeat`;
        item.style.backgroundSize = "100% 100%";
      }
    });
    // !招财猫
    // ele.zhaocm = $("#zhaocm");
    let zhaocm = document.querySelectorAll("#zhaocm");

    zhaocm.forEach((item) => {
      item.onclick = () => {
        // 刘欣 引导 招财猫 2023-6-22 14:53:04
		let ugid = guide.getUsersGuideId("userGuideId");
        if (~[129].indexOf(ugid)) guide.hideCentury_129();
        if (obj.gj_num == 1 && obj.is_z == 0 && my_house.type == 1) {
          location.href = `../page/wealReward.html`;
        } else {
          location.href = `../page/wealth.html?${h_id}`;
        }
      };
    });
    // 点击招财猫跳转招财猫页面
    // ele.zhaocm.onclick = () => {

    // };
    // !如果是廉租房,招财进宝没有----------------------
    if (h_id == 1) {
      zhaocm.forEach((item) => {
        closeMdl(item);
      });
    }
    // !是否显示公告
    if (h_id == 1) {
      closeMdl(ele.activity_bottom);
    }
    // !退租
    let tuichu = document.querySelectorAll("#tuichu");
    tuichu.forEach((item) => {
      item.onclick = () => {
        if (item.style.display == "block") {
          // 刘欣 引导 退租
		let ugid = guide.getUsersGuideId("userGuideId");
          if (~[108, 109].indexOf(ugid)) guide.hideCheap_108();
          if (item.dataset.type == 3) {
            // openTips("请联系房东任命别人为管家后再尝试！");
            uid = item.dataset.id;
            openMdl(ele.modal_fangguan);
          } else {
            openMdl(ele.modal_tuizu);
          }
        }
      };
    });
    // !房东点击退出
    let tuichufangAll = document.querySelectorAll("#tuichufang");
    tuichufangAll.forEach((item) => {
      item.onclick = () => {
        if (obj.gj_num < 1 && h_id == 3) {
          openTips("请先任命管家，才能退出");
        } else if (obj.gj_num < 1 && h_id == 4) {
          openTips("请先任命管家，才能退出");
        } else if (obj.gj_num < 1 && h_id == 2) {
          openTips("楼主不可退租");
        } else {
          openMdl(ele.modal_tuizu);
        }
      };
    });
    // !点击跳转装修
    let zhuangxiuAll = document.querySelectorAll("#zhuangxiu");
    zhuangxiuAll.forEach((item) => {
      item.onclick = () => {
        // 刘欣 引导 进入装修 2023-6-22 14:17:25
		let ugid = guide.getUsersGuideId("userGuideId");
        if (~[126].indexOf(ugid)) guide.hideCentury_126();
        location.href = `../page/renovation.html?${h_id}`;
      };
    });
    // todo房东点击设置按钮
    let settingAll = document.querySelectorAll("#setting");
    settingAll.forEach((ite) => {
      // todo判断是否有管家
      if (ite.dataset.type == 3) {
        is_guan = 1;
      }
      if (
        ite.dataset.type == 1 ||
        ite.dataset.type == 3 ||
        ite.dataset.type == 2
      ) {
        // !租客的数量
        ele.zuke.innerHTML = `租客(${ite.dataset.user}/${ite.dataset.zf})`;
      }
    });
    settingAll.forEach((item) => {
      item.onclick = () => {
        // *复制id
        uid = item.dataset.id;
        // *判断是否为管家
        type = item.dataset.type;
        // *判断是否为禁租1则为禁租
        is_jin = item.dataset.jin;
        // !是否有管家
        if (is_guan == 1) {
          ele.title_guan.innerHTML = `管家(1/1)`;
        } else {
          ele.title_guan.innerHTML = `管家(0/1)`;
        }
        // !渲染对勾
        if (item.dataset.jin == 1) {
          closeMdl(ele.guanjiaDui);
          closeMdl(ele.guanjiaZuke);
          ele.guanjiaId.innerHTML = ` <img src="http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/guanjia2.png" alt="" />`;
          ele.jinImg.innerHTML = `  <img class="jinzhi_img" src="http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/jinzhituhui.png"  alt="" />`;
        } else {
          ele.guanjiaId.innerHTML = ` <img src="http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/guanjia1.png" alt="" />`;
          ele.jinImg.innerHTML = `  <img class="jinzhi_img" src="http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/jinzhi.png"  alt="" />`;
        }
        if (item.dataset.type == 2) {
          // 租客
          if (item.dataset.jin == 1) {
            closeMdl(ele.guanjiaDui);
            closeMdl(ele.guanjiaZuke);
          } else {
            openMdl(ele.guanjiaZuke);
            closeMdl(ele.guanjiaDui);
          }
        } else if (item.dataset.type == 3) {
          // 房管
          closeMdl(ele.guanjiaZuke);
          openMdl(ele.guanjiaDui);
        }

        // !清退倒计时
        if (item.dataset.jin == 1) {
          if (item.dataset.time) {
            openMdl(ele.dwts);
            let timeC = setInterval(() => {
              let newTime = +new Date();
              if (newTime >= item.dataset.time * 1000) {
                clearInterval(timeC);
              }
              ele.dwts.innerHTML = `<p>清退倒计时</p>
              <p>${getCountTime(item.dataset.time)}</p>`;
            }, 1000);
          }
        } else {
          closeMdl(ele.dwts);
        }
        openMdl(ele.modal_operate);
      };
    });
    // !付费房产点击禁止续租
    ele.renewal.onclick = () => {
      if (is_jin == 1) {
        openTips("已禁止续租");
      } else {
        blockZu({
          l_id: l_id,
          h_id: h_id,
          uid: uid,
        });
      }
    };
    // !付费房产点击租客
    ele.zukeBtn.onclick = () => {
      identity({
        l_id: l_id,
        h_id: h_id,
        uid: uid,
        type: 2,
      });
    };
    // !付费房产点击管家
    ele.guanjiaId.onclick = () => {
      identity({
        l_id: l_id,
        h_id: h_id,
        uid: uid,
        type: 3,
      });
    };

    // todo点击禁止续租
    let prohibitAll = document.querySelectorAll("#prohibit");
    prohibitAll.forEach((item) => {
      item.onclick = (e) => {
        // 打开弹窗
        ele.zh_name.innerHTML = `确定要禁止${item.dataset.name}续约吗？`;
        uid = item.dataset.id;
        openMdl(ele.modal_prohibit);
      };
    });
    // todo点击关闭禁用弹框x号
    ele.chahao4.onclick = () => {
      closeMdl(ele.modal_prohibit);
    };
    //! 获取消息提示标签长度
    ele.tishi_p = $("#tishi_p");
    ele.tongzhi = $("#tongzhi");
    ele.tishi_p.innerHTML = data.message;
    if (ele.tishi_p.scrollWidth > ele.tongzhi.clientWidth) {
      ele.tishi_p.className = "tishi_p";
      ele.tishi_p.style.marginLeft = `${ele.tongzhi.clientWidth}px`;
    } else {
      ele.tishi_p.className = "tishi_p2";
    }
    // !到期时间
    let time_daoqi = document.querySelectorAll("#time_daoqi");
    time_daoqi.forEach((item) => {
      if (item.dataset.id == 1) {
        let statTime = setInterval(() => {
          if (item.dataset.time * 1000 <= +new Date()) {
            clearInterval(statTime);
            item.innerHTML = ` `;
            return;
          }
          item.innerHTML = `到期时间：${getCountTimeDay(item.dataset.time)}`;
        }, 1000);
      }
    });
    // !房东点击续租
    // 渲染续租
    if (h_id == 2) {
      ele.xuzuMoney.innerHTML = `租金：${obj.xz_money}金币/天`;
      ele.zongNum.innerHTML = obj.xz_money * numX;
      ele.chengName.innerHTML = obj.house_name;
      ele.xuzu = $("#xuzu");
      ele.xuzu.onclick = () => {
        openMdl(ele.modal_lease);
      };
    }
  }
  // !房东更改公告
  function messageFang(data) {
    let token = getCookie("token");
    ajax({
      method: "post",
      url: API_PATH.MESSAGE,
      header: {
        Authorization: token,
      },
      data: {
        message: data,
        l_id: l_id,
        h_id: h_id,
      },
      success: (res) => {
        openTips(res.msg);
        if (res.code == 1) {
          ele.textarns.value = "";
          closeMdl(ele.modal_textarn);
          // 在请求一次
          initAsync();
        }
      },
      error: (err) => {
        // openTips(err.msg);
      },
    });
  }
  // !房东续租的方法
  // xuzuFang();
  function xuzuFang() {
    let token = getCookie("token");
    ajax({
      method: "post",
      url: API_PATH.XUZU,
      header: {
        Authorization: token,
      },
      data: {
        num: numX,
      },
      success: (res) => {
        openTips(res.msg);
        if (res.code == 1) {
          initAsync();
          closeMdl(ele.modal_lease);
        }
      },
      error: (err) => {
        // openTips(err.msg);
      },
    });
  }
  // !世纪城房东拉黑租客方法
  function blockZu(data) {
    let token = getCookie("token");
    ajax({
      method: "post",
      url: API_PATH.BLOCKZU,
      header: {
        Authorization: token,
      },
      data: data,
      success: (res) => {
        openTips(res.msg);
        if (res.code == 1) {
          initAsync();
          // 关闭弹窗
          closeMdl(ele.modal_operate);
          closeMdl(ele.modal_prohibit);
          closeMdl(ele.modal_fangguan);
        }
      },
      error: (err) => {
        // openTips(err.msg);
      },
    });
  }
  // !世纪城房东拉黑租客方法
  function identity(data) {
    let token = getCookie("token");
    ajax({
      method: "post",
      url: API_PATH.AUTHORITY,
      header: {
        Authorization: token,
      },
      data: data,
      success: (res) => {
        openTips(res.msg);
        if (res.code == 1) {
          initAsync();
          // 关闭弹窗
          closeMdl(ele.modal_operate);
        }
      },
      error: (err) => {
        // openTips(err.msg);
      },
    });
  }
  // !切换背景图片的方法
  function bg(num) {
    if (h_id == 1) {
      return "5";
    }
    if (num < 100) {
      if (h_id == 1) {
        return "15";
      }
      return "11";
    } else if (100 <= num < 200) {
      return "12";
    } else if (200 <= num < 300) {
      return "13";
    } else if (300 <= num) {
      return "14";
    }
  }
  // !时间判断
  function offline(time) {
    if (!time) {
      return `<b class='li'>离线</b>`;
    }
    let ayncTime = +new Date(time);
    let newTime = +new Date();
    let timeZong = ayncTime + 900000;
    let count = (newTime - timeZong) / 1000;
    let day = parseInt(count / 60 / 60 / 24);
    // 时
    let h = parseInt((count / 60 / 60) % 24);
    if (newTime <= timeZong) {
      return "<b class='zai'>在线</b>";
    } else {
      return `<b class='li'>${day}天${h}小时前</b>`;
    }
  }
})();
